package com.compass.doctor.ui.chat.attachment

import com.compass.doctor.R
import com.compass.framework.constant.ARTICLE_CODE
import com.compass.framework.utils.getStringFromResource
import com.netease.yunxin.kit.corekit.im.custom.CustomAttachment
import org.json.JSONObject

/**
 * Description： 自定义文章消息
 * Date:2024/1/19 10:52
 */
class ArticleAttachment : CustomAttachment(ARTICLE_CODE) {
    private var title: String=""
    private var converImg: String? = null
    private var name: String? = null
    private var avatar: String? = null
    private var positionName: String? = null
    private var id: String? = null
    private var columnType: String? = null //1图文 2视频


    //重写数据解析方法，这里面数据以JSONObject格式进行传输，所以您可以制定自己的数据格式。
    //这个示例表示，自定义数据格式为{"customer_message_key":"我是一个自定义消息"}
    override fun packData(): JSONObject {
        var data = JSONObject()
        data.put("title", title)
        data.put("converImg", converImg)
        data.put("name", name)
        data.put("avatar", avatar)
        data.put("positionName", positionName)
        data.put("id", id)
        data.put("columnType", columnType)

        return data
    }


    override fun parseData(jsonObject: JSONObject?) {
        // 从接收到的消息内容中解析您的数据
        jsonObject?.let {
            this.title = jsonObject.getString("title")
            this.converImg = jsonObject.getString("converImg")
            this.name = jsonObject.getString("name")
            this.avatar = jsonObject.getString("avatar")
            this.positionName = jsonObject.getString("positionName")
            this.id = jsonObject.getString("id")
            this.columnType = jsonObject.getString("columnType")

        }

    }


    /**
     * 设置文章消息内容
     */
    fun setArticleData(
        title: String,
        content: String,
        img: String,
        doctorName: String,
        avatar: String,
        professional: String
    ) {


    }


    override fun getContent(): String? {
        return getStringFromResource(R.string.attachment_article_msg)
    }

    fun getTitle(): String {
        return title
    }

    fun getDoctorName(): String? {
        return name
    }

    fun getConverImg(): String? {
        return converImg
    }

    fun getDoctorAvatar(): String? {
        return avatar
    }

    fun getDoctorTitle(): String? {
        return positionName
    }

    fun getId(): String? {
        return id
    }

    fun getColumnType(): String? {
        return columnType
    }

}